package com.lwz.common.kotlin

/**
 * @Description: 类作用描述
 * @Author: chad
 * @CreateDate: 2025/5/8 20:29
 * @Version: 1.0
 */
fun doSomething() {
    println("doSomething")
}

sealed class Result
class Success(val msg: String) : Result()
class Error(val error: Exception) : Result()

fun doSomething2(result: Result): String {
    return when (result) {
        is Success -> result.msg
        is Error -> result.error.message ?: "未知错误"
    }
}

/**
 * 连续比较大小
 */
fun getMax(vararg num:Int):Int {
    var max = Int.MAX_VALUE
    for (i in num) {
        max = kotlin.math.max(max,i)
    }
    return max
}

fun <T:Comparable<T>> getMax2(vararg num:T):T {
    if (num.isEmpty()) throw IllegalArgumentException("参数不能为空")
    var max = num[0]
    for (i in num) {
        if (i > max){
            max = i
        }
    }
    return max
}

